var demandHandle = new Vue({
	el:"#demand-handle-content",
	data: function() {
		return {
			demaindid: '',
			type: '',
			process: '',
			corsystem: '',
			demander: '',
			depart: '',
			workshop: '',
			phone: '',
			email: '',
			content: '',
			recorder: '',
			recorderDate: '',
			solutionError: '',
			solution: ''
		}
	},
	mounted: function () {
		var self = this;
		mui.init();
		mui.plusReady(function() {
			self.initValidator();
			self.initLayout();
			self.initData();
		})
	},
	methods:{
		initValidator: function() {
			this.constraints = {
				solution: {
					length: {
						maximum: 80,
						message: "长度不能超过80"
					}
				},
			};
		},
		initData: function () {
			var thisPage = plus.webview.currentWebview();
			var thisData = thisPage.data;
			
			this.demaindid = thisData.id;
			this.type = thisData.type;
			this.process = thisData.process;
			this.corsystem = thisData.corsystem;
			this.demander = thisData.demander;
			this.depart = thisData.depart;
			this.workshop = thisData.workshop;
			this.phone = thisData.phone;
			this.email = thisData.email;
			this.content = thisData.content;
			this.recorder = thisData.recorder;
			this.recorderDate = thisData.recorddate ? thisData.recorddate.split('T')[0] : '';
		},
		initLayout:function() {
			mui('.mui-scroll-wrapper').scroll({
				scrollY: true, //是否竖向滚动
				scrollX: false, //是否横向滚动
				startX: 0, //初始化时滚动至x
				startY: 0, //初始化时滚动至y
				indicators: true, //是否显示滚动条
				deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
				bounce: true //是否启用回弹
			})
		},
		closeDemand: function() {
			var data = {};
			var self = this;
			if(this.solution) {
				data['solution'] = this.solution;
			}
			var errors = validate(data, this.constraints);
			
			if(errors) {
				if(errors.solution) {
					this.solutionError = errors.solution;
				}
			} else {
				mui.confirm('确定关闭这条需求信息?','确认',['取消','确认'],function (e) {
					if(Number(e.index) == 1) {
						self.submitData();
					}
				},'div');
			}
		},
		submitData: function() {
			var sef = this;
			var url = config.requestBaseUrl + "closeDemand";
			mui.ajax(url,{
				data:{
					demaindid: this.demaindid,
					solution: this.solution
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:3000,//超时时间设置为10秒；
				success:function(data){
					mui.toast(data.msg);
					if(data.isSuccess) {
						var indexPage = plus.webview.getLaunchWebview();
						mui.fire(indexPage,'refresh',{});
						
						var thisPage = plus.webview.currentWebview();
						thisPage.close();
					}
				},
				error:function(xhr,type,errorThrown){
					mui.toast("出错啦!" + errorThrown);
				}
			});
		}
	}
})